package com.centling;

import org.springframework.context.annotation.Configuration;
import org.springframework.messaging.simp.config.MessageBrokerRegistry;
import org.springframework.web.socket.config.annotation.AbstractWebSocketMessageBrokerConfigurer;
import org.springframework.web.socket.config.annotation.EnableWebSocketMessageBroker;
import org.springframework.web.socket.config.annotation.StompEndpointRegistry;

/**
 * Created by centling on 2017/4/12.
 */
@Configuration
@EnableWebSocketMessageBroker   //开始启用stomp协议来传输基于代理的消息
public class WebSocketConfig extends AbstractWebSocketMessageBrokerConfigurer
{
    @Override
    public void registerStompEndpoints(StompEndpointRegistry stompEndpointRegistry)//表示注册STOMP协议的节点，并指定映射的URL。
    {
        //这一行代码用来注册STOMP协议节点，同时指定使用SockJS协议
        stompEndpointRegistry.addEndpoint("/endpoinSang").withSockJS();
    }

    @Override
    public void configureMessageBroker(MessageBrokerRegistry registry)//.configureMessageBroker方法用来配置消息代理，由于我们是实现推送功能，这里的消息代理是/topic
    {
        registry.enableSimpleBroker("/topic");
    }

}
